﻿using CL_SQL;
using CL_SQL.BLL;
using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace StudentLoan.Controllers
{
    public class NoticeController : Controller
    {
        NoticeBLL nb = new NoticeBLL();
        // GET: Notice
        public ActionResult Notice()
        {
            return View();
        }
        public void AllNotice()
        {
            var pageNumber = Convert.ToInt32(Request.Params["page"]);
            var pageSize = Convert.ToInt32(Request.Params["rows"]);

            List<Notice> list = new List<Notice>();
            list = nb.AllNotice();

            Hashtable ht = new Hashtable
            {
                {"total",list.Count()},
                {"rows", list.Take(pageNumber*pageSize).Skip((pageNumber-1)*pageSize).ToList<Notice>()}
            };
            HttpContext.Response.Write(JsonConvert.SerializeObject(ht));
        }

        [ValidateInput(false)]
        [HttpPost]
        public void Add()
        {

            Notice notice = new Notice();
            notice.Title = Request.Form["Title"];//= Server.HtmlDecode(param.Detail);
            notice.Context = Server.HtmlDecode(Request.Form["Context"].ToString());
            notice.ReleaseTime = DateTime.Now;
            notice.Author = "张三";
            if (nb.Add(notice))
            {
                HttpContext.Response.Write(0);
            }
            else
            {
                HttpContext.Response.Write(1);

            }
            HttpContext.Response.End();
        }
    }
}